package com.hongyun.tms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hongyun.tms.common.dto.tug.TmsMTugQueryDto;
import com.hongyun.tms.common.vo.CrewCertVO;
import com.hongyun.tms.common.vo.PordWorkVO;
import com.hongyun.tms.common.vo.TmsMTugVO;
import com.hongyun.tms.entity.TmsMTug;
import com.hongyun.tms.mapper.ScreenMapper;
import com.hongyun.tms.service.ScreenService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;

/**
 * 拖轮信息表
 *
 * @author yuheng
 * @since 1.0.0 2024-06-06
 */
@Service
public class ScreenServiceImpl extends ServiceImpl<ScreenMapper, HashMap> implements ScreenService {

    private LambdaQueryWrapper<TmsMTug> getWrapper(TmsMTugQueryDto query) {
        LambdaQueryWrapper<TmsMTug> wrapper = Wrappers.lambdaQuery();
        wrapper.like(StringUtils.isNotBlank(query.getTugName()), TmsMTug::getTugName, query.getTugName())
                .like(StringUtils.isNotBlank(query.getCallNo()), TmsMTug::getCallNo, query.getCallNo())
                .eq(query.getStaus() != null, TmsMTug::getStaus, query.getStaus())
                .eq(StringUtils.isNotBlank(query.getTugTypeCode()), TmsMTug::getTugTypeCode, query.getTugTypeCode())
                .eq(StringUtils.isNotBlank(query.getPortAreaCode()), TmsMTug::getPortAreaCode, query.getPortAreaCode())
                .orderByDesc(TmsMTug::getBuildDate);
        return wrapper;
    }

    @Override
    public List<HashMap<String, Object>> getFeeList(String planDte) {
        if(!StringUtils.isEmpty(planDte)){
            return baseMapper.getFeeListMon(planDte);
        }else{
            return baseMapper.getFeeListYear();
        }
    }

    @Override
    public List<TmsMTugVO> getTmsMTug() {
        return baseMapper.getTmsMTug();
    }

    @Override
    public List<PordWorkVO> getTmsMTugWork() {
        return baseMapper.getTmsMTugWork();
    }
    @Override
    public List<HashMap<String, Object>> getConsumeTmsMTug(String planDte) {
        if(!StringUtils.isEmpty(planDte)){
            return baseMapper.getConsumeTmsMTugMon(planDte);
        }else{
            return baseMapper.getConsumeTmsMTugYear();
        }
    }

    @Override
    public List<HashMap<String, BigDecimal>> getWorkNum(String planDte) {
        if(!StringUtils.isEmpty(planDte)){
            return baseMapper.getWorkNumMon(planDte);
        }else{
            return baseMapper.getWorkNumYear();
        }
    }

    @Override
    public List<HashMap> getTmsMTugCargo(String planDte) {
        if(!StringUtils.isEmpty(planDte)){
            return baseMapper.getTmsMTugCargoMon(planDte);
        }else{
            return baseMapper.getTmsMTugCargoYear();
        }

    }

    @Override
    public List<HashMap> getTmsMTugCorp(String planDte) {
        if(!StringUtils.isEmpty(planDte)){
            return baseMapper.getTmsMTugCorpMon(planDte);
        }else{
            return baseMapper.getTmsMTugCorpYear();
        }
    }

    @Override
    public List<CrewCertVO> getTmsCrewCert() {
        return baseMapper.getTmsCrewCert();
    }
}
